package org.yjh.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.yjh.pojo.User;

import java.util.List;

@Mapper
public interface UserDao {

    @Select("select uid,uname,password from user where uname=#{uname} and password=${password}")
    public User getLogin(@Param("uname") String uname, @Param("password") String password);

    @Select("update user set ucookie = #{cookie} where uid =#{uid}")
    public void setCookie(@Param("cookie") String cookie,@Param("uid") int uid);

    @Select("select ucookie from user where uid = #{uid}")
    public User getCookie(@Param("uid") int uid);

    @Select("select uid,uname,utype,ucookie from user where uid = #{uid}")
    public User getUser(@Param("uid") int uid);

    @Select("select uid from user where uname=#{uname}")
    public User getUserByName(@Param("uname") String uname);

    @Select("insert into user(uname,password) values(#{uname},#{password})")
    public User setUser(User u);

//    @Select("select uid,uname,utype from user where uid=#{uid} and uname=#{uname} and utype=#{utype}")
    @Select("<script>" +
                "select uid,uname,utype from user where 1=1 " +
                "<if test=\" uid !=0 \" > and uid=#{uid} </if>"+
                "<if test=' uname !=null and uname != \"\" ' > and uname like CONCAT('%',#{uname},'%') </if>"+
                "<if test=\" utype !=999 \" > and utype=#{utype} </if>"+
            "</script>")
    public List<User> getUserAsConditions(User u);


}
